package org.stvd.repository.common.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.stvd.entities.common.WebReflect;
import org.stvd.entities.common.WebReflectPK;
import org.stvd.repository.base.impl.BaseDaoImpl;
import org.stvd.repository.common.WebReflectDao;

/**
 * 前台映射Repository实现类
 * @author houzx
 */
@Repository("WebReflectDao")
public class WebReflectDaoImpl extends BaseDaoImpl<WebReflect> implements WebReflectDao {
    
    @Transactional
    public void delete(final WebReflectPK webReflectPK) {
        this.em.remove(this.em.find(WebReflect.class, (Object) webReflectPK));
    }

    public WebReflect findByPK(final WebReflectPK webReflectPK) {
        String hql  = " FROM WebReflect WHERE (requestUrl = ?0 OR '' = ?0) AND (requestMethod = ?1 OR '' = ?1)";
        List<WebReflect> list = findByHQL(hql, webReflectPK.getRequestUrl(), webReflectPK.getRequestMethod());
        if(list!=null && list.size() > 0){
            return list.get(0);
        }
        return null;
    }
}
